﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;

namespace Lizk.Media
{
    public abstract class TypeScanner
    {
        public string Type { get; set; }
        public List<string> VideoExtensions { get; private set; }
        public List<string> DiscImageExtensions { get; private set; }
        public List<string> PictureExtensions { get; private set; }

        public TypeScanner(string type)
        {
            this.Type = type;
            VideoExtensions = new List<string>(MediaUtil.BasicVideoExtensions);
            DiscImageExtensions = new List<string>(MediaUtil.BasicDiscImageExtensions);
            PictureExtensions = new List<string>(MediaUtil.BasicPictureExtensions);
        }

        public abstract void Scan(string rootPath, Predicate<VideoData> exists, Action<VideoData> mediaAdded);

        protected string GetVideoType(string filename)
        {
            filename = filename.ToLower();
            string fext = Path.GetExtension(filename);
            if (fext.Length == 0)
                return null;
            fext = fext.Substring(1);

            if (filename == "video_ts.ifo")
                return "video_ts";

            if (VideoExtensions.Contains(fext))
                return "media";


            if (DiscImageExtensions.Contains(fext))
                return "media";

            return null;
        }
    }
}
